# 原php包依赖于debian jessie
FROM php:7.1-fpm
MAINTAINER Jin<cpp@strcpy.cn>

# 更新镜像源
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak
COPY docker-file/sources.list.jessie /etc/apt/sources.list

# 时区
RUN echo "Asia/Shanghai" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata

# 安装包
RUN apt-get update \
    && apt-get install -y libcurl4-openssl-dev \
                            libssl-dev \
                            libmcrypt-dev \
                            libpng-dev \
                            libjpeg-dev \
                            libfreetype6-dev \
                            libpng12-dev \
                            git

# 安装php扩展
RUN pecl install -o -f redis mongodb && \
    rm -rf /tmp/pear && \
    docker-php-ext-enable redis mongodb

RUN docker-php-ext-configure gd --enable-gd-native-ttf \
                                --with-freetype-dir=/usr/include/freetype2 \
                                --with-png-dir=/usr/include \
                                --with-jpeg-dir=/usr/include

RUN docker-php-ext-install pdo \
                            pdo_mysql \
                            session \
                            sockets \
                            bcmath \
                            opcache \
                            calendar \
                            mcrypt \
                            hash \
                            mysqli gd

# 创建目录
RUN set -ex && \
    mkdir -p /var/www/app /tmp/log /var/www/cache /var/run/php7-fpm

# 设置工作目录
WORKDIR /var/www/app

# 添加测试文件
COPY docker-file/phpinfo.php /var/www/app/index.php

# 设置目录权限
RUN chown -R www-data:www-data /tmp/log /var/www/cache /var/www/app /var/run/php7-fpm && \
    chmod -R +w /tmp/log /var/www/cache /var/www/app /var/run/php7-fpm && \
    ls -lh && cat index.php && pwd

# 复制配置文件
COPY docker-file/php.ini /usr/local/etc/php
COPY docker-file/php-fpm.conf /usr/local/etc/php
COPY docker-file/php-fpm.d /usr/local/etc/php-fpm.d

# 清理一下空间
RUN set -ex && \
    apt-get autoremove -y && \
    apt-get clean

RUN git clone -b v2.0.9 https://gitee.com/swoole/swoole.git \
    && cd swoole \
    && /usr/local/bin/phpize \
    && ./configure \
    && make \
    && make install \
    && echo "extension=swoole.so" >> /usr/local/etc/php/php.ini \
    && rm -rf swoole

EXPOSE 9000